//body.onload初始化
//boolean logged: 是否登入
//boolean verified: 是否已驗證E-Mail
//boolean homepage: 是否為首頁
function init(){
	//Initialize Message Style
	Message.init("msg-block", "msg-title", "msg-content", "msg-action", "button", null, Button.eventHandler);
	
	//Initialize Form
	Account.Register.init("form-register");
	Account.Login.init("form-login");
	Account.MessageCreate.init("form-message-create");
}

//轉址至首頁
function goHome(){
	document.location = "/";
}

//登出
function logout(){
	Message.show("msg-logout", 400, "登出中", Ajax.loadingImg);
	Ajax.sendRequest(
		"post", "/exe/Logout", "", true, 
		function(req){
			Message.show("msg-logout-result", 400, "登出成功", "您已成功登出", Button.buttonReload);
		}
	);
}
//聯絡我們
function contact(form){
	if(form.subject.value == ""){
		Message.show("msg-contact-check", 400, "主旨格式錯誤", "請填寫主旨", Message.BUTTON_OK);
		return;
	}
	if(form.subject.value.length > 30){
		Message.show("msg-contact-check", 400, "主旨格式錯誤", "主旨字元數不得超過 30 字元", Message.BUTTON_OK);
		return;
	}
	if(form.content.value == ""){
		Message.show("msg-contact-check", 400, "內容格式錯誤", "請填寫內容", Message.BUTTON_OK);
		return;
	}
	if(form.content.value.length > 255){
		Message.show("msg-contact-check", 400, "內容格式錯誤", "內容字元數不得超過 255 字元", Message.BUTTON_OK);
		return;
	}
	
	Message.show("msg-contact-processing", 400, "系統處理中", Ajax.loadingImg);
	Ajax.sendRequest(
		"post", "/exe/member/Contact", 
		"subject=" + encodeURIComponent(form.subject.value) + "&content=" + encodeURIComponent(form.content.value), true,
		function(req){
			Message.hide("msg-contact-processing");
			var result = req.getResponseHeader("result");
			if(result == "true"){
				Message.show("msg-contact-result", 400, "送出成功", "您的訊息已成功送出，我們會盡快處理。", Button.buttonReload);
			}else{
				Message.show("msg-contact-result", 400, "系統錯誤", "請稍後重試或聯絡客服", Message.BUTTON_OK);
			}
		}
	);
}